private readonly IUnitOfWork _unitOfWork;
public HomeController(ILogger<HomeController> logger, IUnitOfWork unitOfWork)
{
_logger = logger;
_unitOfWork = unitOfWork;
}
public IActionResult Index()
{
List<Product> objProductList = _unitOfWork.Product.GetAll(includeProperties: "Category").ToList();
return View(objProductList);
}
@model IEnumerable
<div class="row pb-3">
@foreach (var product in Model)
{
<div class="col-lg-3 col-md-6">
<div class="row p-2">
<div class="col-12 p-1" style="border:1px solid #008cba; border-radius: 5px">
<div class="card">
<img src="@product.ImageUrl" class="card-img-top rounded">
<div class="card-body">
<div class="p-1">
<p class="card-title h5 text-primary">@product.Name</p>
<p class="card-title text-secondary"><b>@product.Size</b></p>
</div>
<div class="p-1">
<p>價格:<b>$@product.Price.ToString("0.00")</b></p>
</div>
</div>
</div>
<div>
<a asp-action="Details" class="btn btn-primary form-control" asp-route-productId="@product.Id">
Details
</a>
</div>
</div>
</div>
</div>
}
</div>